package com.company.project.utils;

import org.apache.commons.lang.RandomStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @author talentle
 * @date 2019/11/15 10:28
 * @describe 随机生成编码
 */
public class RandomUtil {

  /**
   * 随机生成数字
   *
   * @param num 生成几位数
   * @return
   */
  public static String randomNumeric(int num) {
    return RandomStringUtils.randomNumeric(num);
  }

  /**
   * 随机生成字母和数字组合(去I、O字母)
   *
   * @param num
   * @return
   */
  public static String randomString(int num) {
    String str = "ABCDEFGHJKLMNPQRSTUVWXYZ0123456789";
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < num; i++) {
      int number = random.nextInt(str.length());
      sb.append(str.charAt(number));
    }
    return sb.toString();
  }

  /**
   * 生成批次号
   *
   * @return
   */

  public static String generateBatchNumber() {
    Date currentDate=new Date();
    SimpleDateFormat smf=new SimpleDateFormat("yyMMdd");
    String code =smf.format(currentDate);
    return code;
  }
  /**
   * 生成出库编码
   *
   * @return
   */

  public static String generateSocktOutCode() {
    Date currentDate=new Date();
    SimpleDateFormat smf=new SimpleDateFormat("yyyyMMddHHmmss");
    String code ="CK"+smf.format(currentDate);
    return code;
  }

  /**
   * 生成入库编码
   *
   * @return
   */

  public static String generateSocktInCode() {
    Date currentDate=new Date();
    SimpleDateFormat smf=new SimpleDateFormat("yyyyMMddHHmmss");
    String code ="RK"+smf.format(currentDate);
    return code;
  }

  /**
   * 生成采购编码
   *
   * @return
   */

  public static String generatePurchaseCode() {
    Date currentDate=new Date();
    SimpleDateFormat smf=new SimpleDateFormat("yyyyMMddHHmmss");
    String code ="CG"+smf.format(currentDate);
    return code;
  }

  /**
   * 生成销售单编码
   *
   * @return
   */

  public static String generateSalesCode() {
    Date currentDate=new Date();
    SimpleDateFormat smf=new SimpleDateFormat("yyyyMMddHHmmss");
    String code ="XS"+smf.format(currentDate);
    return code;
  }

  /**
   * 生成售后单编码
   *
   * @return
   */

  public static String generateAfterSalesCode() {
    Date currentDate=new Date();
    SimpleDateFormat smf=new SimpleDateFormat("yyyyMMddHHmmss");
    String code ="SH"+smf.format(currentDate);
    return code;
  }


}
